package com.sxfans.json;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.ezmorph.object.DateMorpher;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.util.JSONUtils;

public class JsonTest {
	public static void main(String[] args) {
		User user = new User();
		user.setUsername("admin");
		user.setPwd("admin");
		
		Role role = new Role();
		List list = new ArrayList();
		list.add(role);
		list.add(role);
		list.add(role);
		
		role.setRoleName("test");
		role.setTime(new Date());
		
		List list2 = new ArrayList();
		Menu menu = new Menu();
		menu.setMenuName("caidan");
		list2.add(menu);
		list2.add(menu);
		list2.add(menu);
		role.setListMenu(list2);
		user.setRoleList(list);
		
		JSONObject object = JSONObject.fromObject(user);
		//System.out.println(object);
		
		Map<String,Class> map = new HashMap<String,Class>();
		map.put("roleList", Role.class);
		map.put("listMenu",Menu.class );
		
		User u = (User) JSONObject.toBean(object, User.class,map);
		System.out.println(u.getRoleList().get(0).getTime());
	}
}
